<include file="Template:pageheader"/>

<form id="nodeForm" method="post" action="__URL__/addroleOk">
	<table>
		<tr>	
			<td>{$lang.role_name}</td>
			<td><input type="text" class="input" name="name" /></td>
		</tr>
		<tr>	
			<td>{$lang.status}</td>
			<td><input type="checkbox" name="status" value="1"/></td>
		</tr>
		<tr>	
			<td>{$lang.remark}</td>
			<td><input type="text" class="input" name="remark" value=""/></td>
		</tr>			
	</table>
	<!-- [权限列表] -->
	<table>
		<volist name="controllerList" id="controller">
			<tr>
				<td>
					{$controller.blank}
					<input type="checkbox" 
						   datas="{$controller.id}_{$controller.name}-{$controller.pid}_{$controller.p_name}" 
						   onclick="check('{$controller.id}_{$controller.name}','{$controller.pid}_{$controller.p_name}',{$controller.level},this);" 
						   name="chkGroup[]" 
						   value="{$controller.id}-{$controller.level}-{$controller.pid}-{$controller.name}"/>
					{$controller.title}
				</td>		
			</tr>	
		</volist>		
	</table>
	<!-- [权限列表] -->
	<label><input type="checkbox" name="checkall" value="checkbox" onclick="checkAll(this.form, this);" class="checkbox" />{$lang.select_all}</label>
	<label><input type="submit" value="{$lang.submit_text}"/></label>
</form>

<script>
	//select all
	function checkAll(frm, checkbox)
	{
	  	for (i = 0; i < frm.elements.length; i++)
	 	{
			if (frm.elements[i].name == 'action[]' || frm.elements[i].name == 'chkGroup[]')
			{
		 	 frm.elements[i].checked = checkbox.checked;
			}
	 	}
	}	
	//select the controller
	function check(str1, str2,level,checkbox)
	{
		var nodeForm	=	document.getElementById('nodeForm');
	  	var inputList	=	nodeForm.getElementsByTagName('input');
		
	  	console.log('查找字符串: ' + str1);
		
		
		switch(level){
			case 1:
				//首先找出与自己想通的二级控制器
				for(var i = 0 ; i < inputList.length; i ++){
			  		//console.log(inputList[i].getAttribute('datas'));
			  		if(inputList[i].name == 'action[]' || inputList[i].name == 'chkGroup[]'){
			  			//查找有没有存在该字符串
			  			var string	=	inputList[i].getAttribute('datas');
			  			if(string.indexOf(str1) > 0){
			  				console.log(inputList[i].getAttribute('datas'));
			  				inputList[i].checked	=	checkbox.checked;
			  				var stringArray			=	string.split('-');
			  				
			  				//console.log(stringArray[0]);
			  				for(var j = 0; j < inputList.length; j ++){
			  					if(inputList[j].name == 'action[]' || inputList[j].name == 'chkGroup[]'){
			  						var _string		=	inputList[j].getAttribute('datas')
			  						if(_string.indexOf(stringArray[0]) > 0){
			  							inputList[j].checked	=	checkbox.checked;
			  						}
			  					}
			  				}
			  			}		  			
			  		}
			  	}
				
			break;
			case 2:
				for(var i = 0 ; i < inputList.length; i ++){
			  		if(inputList[i].name == 'action[]' || inputList[i].name == 'chkGroup[]'){
			  			//alert(inputList[i].getAttribute('datas'));
			  			//console.log(inputList[i].getAttribute('datas'));
			  			var string 	=	inputList[i].getAttribute('datas');
			  			if(string.indexOf(str1) >  0){
			  				inputList[i].checked	=	checkbox.checked;
			  			}
			  		}
			  	}
			break;
			default:break;
		}
		
	}
	
</script>





















<include file="Template:pagefooter"/>